import { AppCTX } from "../../types/koaExtend";
import { createSpokesmanApiMWRouter } from "../../middleware/spokesman-api/brandSpokesmanChecker";
import { isUndefined } from "mmb";
import { getOrderBySerialNumber } from "../../service/orderService"
const router = createSpokesmanApiMWRouter();

// 获取代言的推广订单详情(代言人管理视角)
router.get("/spn/:spokesmanId/order/:orderSerialNumber", async (ctx: AppCTX, next) => {
  const { spokesmanId, orderSerialNumber } = ctx.params;
  const { userId } = ctx;

  const order = await getOrderBySerialNumber(orderSerialNumber);
  if (isUndefined(order)) {
    ctx.throw("invalid orderSerialNumber")
  }
  // 代言人自己发布的活动
  if (order.spokesmanId !== spokesmanId) {
    ctx.throw(403, "no belong current spokesman");
  }

  ctx.body = order;
});

export default router;